<template>
  <div>
    <!-- 面包屑导航条 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据中心</el-breadcrumb-item>
      <el-breadcrumb-item>工序管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-form :model="process" class="demo-form-inline" >
        <el-row :gutter="20">
          <el-form-item>
            <el-col :span="4">
              <el-input placeholder="工序名称" v-model="process.name"></el-input>
            </el-col>
            <el-button plain type="info"@click="sel">搜索</el-button>
            <el-button  type="primary" @click="addProcess">添加工序</el-button>
          </el-form-item>
        </el-row>
      </el-form>
      <el-table
        :data="processList"
        style="width: 100%">
        <el-table-column
          prop="id"
          label=""
          width="90">
        </el-table-column>
        <el-table-column
          prop="code"
          label="编号"
          width="100">
        </el-table-column>
        <el-table-column
          prop="name"
          label="名称"
          width="180">
        </el-table-column>
        <el-table-column
          label="收费方式"
          width="180">
          <template slot-scope="scope">
            {{scope.row.ctype|ctypeFit}}
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="单价"
          width="180">
        </el-table-column>
        <el-table-column
          prop="prePrice"
          label="准备工时单价"
          width="180">
        </el-table-column>
        <el-table-column
          prop="remarks"
          label="描述"
          width="180">
        </el-table-column>
        <el-table-column
          label="操作"
          width="180">
          <!--点击按钮 需要绑定@click的时间 例如 @click="add"-->
          <template slot-scope="scope">
            <el-dropdown split-button type="primary"  size="mini" >
              操作
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item >
                  <el-button type="text" @click="updateProess(scope.row.id)">
                    编辑
                  </el-button>
                </el-dropdown-item>
                <el-dropdown-item style="color: crimson">
                  <el-button type="text" @click="del(scope.row.id)" style="color: crimson">
                    删除
                  </el-button>
                </el-dropdown-item>
                <el-dropdown-item style="color: crimson">
                  <el-button type="text" @click="look(scope.row.id)" >
                    详情
                  </el-button>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>


        </el-table-column>

      </el-table>
    </el-card>
    <el-pagination
      :current-page="page.pagenum"
      :page-size="page.pagesize"
      :page-sizes="[5, 10, 20, 40]"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    name: 'ProcessList',
    data(){
      return{
        processList:[],
        process:{},
        page: {
          pagenum: 0,
          pagesize: 5
        },
        total: 0,
      }
    },
    methods:{
      sel:function () {
        this.$http.post("/process/list/"+ this.page.pagenum + "/" + this.page.pagesize,this.process).then((res)=>{
          this.processList=res.data.result.list;
          this.total = res.data.result.total;
        })
      },
      handleSizeChange: function (val) {
        this.page.pagesize = val;
        this.sel();
      },
      handleCurrentChange: function (val) {
        this.page.pagenum = val;
        this.sel();
      },
      addProcess:function () {
        this.$router.push('/addProcess');
      },
      del:function (id) {
        this.$http.delete('/process/del/'+id).then((res)=>{
          this.processList=res.data.result.list;
          this.$message.success("删除成功");
          this.sel()
        })
      },
      look:function (id) {
        this.$router.push({path:'/lookProcess',query:{id:id}})
      },
      updateProess:function (id) {
        this.$router.push({path:'/updateProcess',query:{id:id}})
      }
    },
    filters:{
      ctypeFit:function (val) {
        if (val=='0'){
          return "按时收费(分钟)"
        }else if (val=='1'){
          return "按件收费(件数)"
        }
      }
    },
    mounted () {
      this.sel();
    }
  }
</script>

<style scoped>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 1280px;
  }
</style>
